package com.shilun.springboot.hello_demo.exception;

import java.util.HashMap;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice(basePackages= {"com.shilun.springboot.hello_demo.controller"})
public class GlobalExceptionHandler {
	private Logger logger = Logger.getLogger(getClass());
	@ExceptionHandler(value=RuntimeException.class)
	@ResponseBody
	public Map<String,Object> resultError(){
		Map<String,Object> result = new HashMap<String,Object>();
		result.put("code", "500");
		result.put("message","系统错误");
		logger.info("全局异常拦截器"+result);
		return result;
	}
	
	//@ExceptionHandler(value=RuntimeException.class)
	//@ResponseBody
	public String resultErrorPage(){
		/*Map<String,Object> result = new HashMap<String,Object>();
		result.put("code", "500");
		result.put("message","系统错误");*/
		return "500.html";
	}
}
